package com.exam.demo.controller;

import com.exam.demo.pojo.Student;
import com.exam.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/student")
//管理学生的类
public class StudentController {
    @Autowired
    private StudentService studentService;

    @RequestMapping("/add")
    //学生注册,成功返回1，否则返回0
    private @ResponseBody int add(@RequestBody Student student){
        return this.studentService.add(student);
    }

    @RequestMapping("/login")
    //学生登录
    private @ResponseBody Boolean login(@RequestParam("stuNo") String stuNo, @RequestParam("stuPwd") String stuPwd){
        return this.studentService.login(stuNo,stuPwd);
    }

    @RequestMapping("/getinfo")
    private @ResponseBody Student getInfo(@RequestParam("stuNo") String stuNo){
        return this.studentService.getInfo(stuNo);
    }

    @RequestMapping("/changeinfo")
    //学生修改个人资料,成功返回1，否则返回0
    private @ResponseBody int changeInfo(@RequestBody Student student){
        return this.studentService.updateStuInfo(student);
    }

    @RequestMapping("/changepwd")
    //学生修改密码,成功返回1，否则返回0
    private @ResponseBody int changePwd(@RequestParam("stuNo") String stuNo,@RequestParam("oldStuPwd") String oldStuPwd,@RequestParam("newStuPwd") String newStuPwd){
        return this.studentService.updateStuPwd(stuNo,oldStuPwd,newStuPwd);
    }

    @RequestMapping("/getstubystuno")
    private @ResponseBody List<Student> getStudentListByStuNo(@RequestParam("stuNo") String stuNo){
        return this.studentService.getStudentListByStuNo(stuNo);
    }

    @RequestMapping("/getstubystuname")
    private @ResponseBody List<Student> getStudentListByStuName(@RequestParam("stuName") String stuName){
        return this.studentService.getStudentListByStuName(stuName);
    }

    @RequestMapping("/getstubystudis")
    private @ResponseBody List<Student> getStudentListByStuDiscipline(@RequestParam("stuDiscipline") String stuDiscipline){
        return this.studentService.getStudentListByStuDiscipline(stuDiscipline);
    }

    @RequestMapping("/getstubystugrade")
    private @ResponseBody List<Student> getStudentListByStuGrade(@RequestParam("stuGrade") String stuGrade){
        return this.studentService.getStudentListByStuGrade(stuGrade);
    }
}
